/**
 * Por Josu� Hernandez.
 * Preconfiguracion del editor grid.
 * 
 * @class Extmx.grid.EditorGridPanel

 * @extends Ext.grid.EditorGridPanel
 * @autor Ing. Josu� Hern�ndez G�mez<br>
 *        joshua@extjs.mx<br>
 *        http://www.joshua.com.mx
 * @fecha octubre 2010. Mexico DF
 * 
 */
Ext.ns("Extmx.grid.EditorGridPanel");

Extmx.grid.EditorGridPanel=Ext.extend(Ext.grid.EditorGridPanel,{
    frame:false,
    border:false,
    loadMask: true,
    
	/**
	 * @cfg Boolean stripeRows Colorea alternativamente las filas del grid
	 */
    stripeRows:true,
	/**
	 * @cfg Number clicksToEdit Clicks para editar, por defecto 1
	 */
    clicksToEdit :1,
    
	/**
	 * @cfg Boolean loadOnRender Bandera que indica si se desea cargar el store al mostrarse el grid.<br>
	 * Por defecto en true
	 */
    loadOnRender:true,
    
    initComponent: function (){
        var _bbar=this._getBbar();
        Ext.apply(this,{
            bbar: (Ext.isEmpty(_bbar))?undefined:_bbar
        });

        Extmx.grid.EditorGridPanel.superclass.initComponent.apply(this,arguments);

        
        this.on({
            scope:this,
            render: function (){
                if(this.loadOnRender)
                    this.load();
            }
        });

        this.relayEvents(this.store,["load","beforeload"]);
    },

    _getBbar: function (){
        return new Ext.PagingToolbar({
                store: this.store,
                displayInfo: true,
                pageSize: Extmx.NUM_PAGINAS,
                displayMsg: 'Desplegando datos {0} - {1} de {2}',
                emptyMsg: "No hay datos que mostrar"
            });
    },
    reload: function (d){
        this.store.reload(d);
    },
    /**
     * Add Records to the Store and fires the {@link #add} event.  To add Records
     * to the store from a remote source use {@link #load}({add:true}).
     * See also {@link #recordType} and {@link #insert}.
     * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects
     * to add to the cache. See {@link #recordType}.
     */
    add : function(records){
        this.store.add(records);
    },
    /**
     * Remove a Record from the Store and fires the {@link #remove} event.
     * @param {Ext.data.Record} record The Ext.data.Record object to remove from the cache.
     */
    remove : function(record){
    	this.store.remove(record);
    },


    /**
     * Remove a Record from the Store at the specified index. Fires the {@link #remove} event.
     * @param {Number} index The index of the record to remove.
     */
    removeAt : function(index){
    	this.store.removeAt(index);
    },


    /**
     * Remove all Records from the Store and fires the {@link #clear} event.
     */
    removeAll : function(){
    	this.store.removeAll();
    },


    /**
     * Inserts Records into the Store at the given index and fires the {@link #add} event.
     * See also {@link #add} and {@link #addSorted}.
     * @param {Number} index The start index at which to insert the passed Records.
     * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects to add to the cache.
     */
    insert : function(index, records){
    	this.store.insert(index, records);
    },


    /**
     * Get the index within the cache of the passed Record.
     * @param {Ext.data.Record} record The Ext.data.Record object to find.
     * @return {Number} The index of the passed Record. Returns -1 if not found.
     */
    indexOf : function(record){
    
    },


    /**
     * Get the index within the cache of the Record with the passed id.
     * @param {String} id The id of the Record to find.
     * @return {Number} The index of the Record. Returns -1 if not found.
     */
    indexOfId : function(id){
    
    },


    /**
     * Get the Record with the specified id.
     * @param {String} id The id of the Record to find.
     * @return {Ext.data.Record} The Record with the passed id. Returns undefined if not found.
     */
    getById : function(id){
    
    },


    /**
     * Get the Record at the specified index.
     * @param {Number} index The index of the Record to find.
     * @return {Ext.data.Record} The Record at the passed index. Returns undefined if not found.
     */
    getAt : function(index){
    	return this.store.getAt(index);
    },
    
    /**
     * Gets the number of cached records.     
     * If using paging, this may not be the total size of the dataset. If the data object     
     * used by the Reader contains the dataset size, then the {@link #getTotalCount} function returns     
     * the dataset size.  Note: see the Important note in {@link #load}.     
     * @return {Number} The number of Records in the Store's cache. */
    getCount: function (){
    	return this.store.getCount();
    },
    
    /**
     * Loads data from a passed data block and fires the {@link #load} event. A {@link Ext.data.Reader Reader}
     * which understands the format of the data must have been configured in the constructor.
     * @param {Object} data The data block from which to read the Records.  The format of the data expected
     * is dependent on the type of {@link Ext.data.Reader Reader} that is configured and should correspond to
     * that {@link Ext.data.Reader Reader}'s {@link Ext.data.Reader#readRecords} parameter.
     * @param {Boolean} append (Optional) true to append the new Records rather the default to replace
     * the existing cache.
     * Note: that Records in a Store are keyed by their {@link Ext.data.Record#id id}, so added Records
     * with ids which are already present in the Store will replace existing Records. Only Records with
     * new, unique ids will be added.
     */
    loadData : function(o, append){
        this.store.loadData(o, append);
    },

    

    /**
     * Loads the Record cache from the configured {@link #proxy} using the configured {@link #reader}.
     *
		Notes:
     * Important: loading is asynchronous! This call will return before the new data has been
     * loaded. To perform any post-processing where information from the load call is required, specify
     * the callback function to be called, or use a {@link Ext.util.Observable#listeners a 'load' event handler}.

     * If using {@link Ext.PagingToolbar remote paging}, the first load call must specify the start and limit
     * properties in the options.params property to establish the initial position within the
     * dataset, and the number of Records to cache on each read from the Proxy.
     * If using {@link #remoteSort remote sorting}, the configured {@link #sortInfo}
     * will be automatically included with the posted parameters according to the specified
     * {@link #paramNames}.

     * @param {Object} options An object containing properties which control loading options:


    *      * params :Object

      An object containing properties to pass as HTTP
           * parameters to a remote data source. Note: params will override any
           * {@link #baseParams} of the same name.

           *

      Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.

    *      * callback : Function

      A function to be called after the Records
           * have been loaded. The callback is called after the load event and is passed the following arguments:

          o      * r : Ext.data.Record[]

          o      * options: Options object from the load call

          o      * success: Boolean success indicator


    *      * scope : Object

      Scope with which to call the callback (defaults
           * to the Store object)

    *      * add : Boolean

      Indicator to append loaded records rather than
           * replace the current cache.  Note: see note for {@link #loadData}

           *
     * @return {Boolean} If the developer provided {@link #beforeload} event handler returns
     * false, the load call will abort and will return false; otherwise will return true.
     */
    load : function(options) {
        this.store.load(options);
    },

    getSeleccionado: function (){
        return this.getSelectionModel().getSelected() ;
    },
    getSeleccionados: function (){
        return this.getSelectionModel().getSelections() ;
    }
});
//para atajo
Extmx.EditorGridPanel=Extmx.grid.EditorGridPanel;
Ext.reg("editorgridmx",Extmx.EditorGridPanel);